package com.atguigu.yygh.hosp.utils;

import com.alibaba.excel.util.StringUtils;
import com.atguigu.yygh.common.exception.YyghException;
import com.atguigu.yygh.common.result.ResultCodeEnum;
import com.atguigu.yygh.common.utils.MD5;
import com.atguigu.yygh.hosp.service.HospitalSetService;

import java.util.Map;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/18 8:20
 */
public class SignUtil {

  // 校验签名
  public static void signVerify(String hoscode, HospitalSetService hospitalSetService, Map<String,Object> parameterMap){
    //必须参数的校验 略
    if (StringUtils.isEmpty(hoscode)){
      throw new YyghException(ResultCodeEnum.PARAM_ERROR);
    }

    // 签名校验
    String paramSignMD5 = (String)parameterMap.get("sign");
    String requestSignMD5 = MD5.encrypt(hospitalSetService.getSignKey(hoscode));
    if (!paramSignMD5.equals(requestSignMD5)){
      throw new YyghException(ResultCodeEnum.SIGN_ERROR);
    }
  }
}
